package com.mt.mtyx.common.utils;

import com.mt.mtyx.entity.base.BaseEntity;
import org.springframework.util.StringUtils;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

/**
 * 帮助类
 *
 * @author WMT
 * @Date 2023/7/17 16:55
 */
public class Helper {

    /**
     * 添加基础属性赋值
     *
     * @param obj
     * @param now
     * @param <T>
     */
    public static <T extends BaseEntity> void setBaseProperties(T obj, LocalDateTime now) {
        obj.setCreateTime(now);
        obj.setUpdateTime(now);
        obj.setIsDeleted(BaseEntity.NOT_DELETED);
    }

    /**
     * 日期转换
     *
     * @param dateTimeString 日期字符串
     * @return 对应日期格式
     */
    public static LocalDateTime parseDateTime(String dateTimeString) {
        if (!StringUtils.isEmpty(dateTimeString)) {
            return LocalDateTime.parse(dateTimeString, DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
        }
        return null;
    }
}
